<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>智能审单规则</title>
    <link rel="stylesheet" href="../assets/plugin/jquery-ui-1.12.1.custom/jquery-ui.css"/>
    <link rel="stylesheet" href="../assets/plugin/layer/skin/default/layer.css"/>
    <link rel="stylesheet" href="../assets/css/rule.css"/>
    <style type="text/css">
    </style>
</head>
<body>
<div class="container-section">
    <div class="main-section">
        <div class="header-section">
            政策提醒新增
        </div>
        <form class="form-horizontal">
            <div class="top-section">
                <table class="top-table">
                    <tbody>
                    <tr>
                        <td class="label-name">关联政策：</td>
                        <td>
                            <select class="select-policy-relation">
                            </select>
                        </td>
                        <!--<td class="label-name">状态：</td>
                        <td class="label-content">
                            <select class="select-policy-status">
                                <option value="0">草稿</option>
                                <option value="1">生效</option>
                                <option value="-1">失效</option>
                            </select>
                        </td>
                        <td class="label-name">生效时间：</td>
                        <td class="label-content"><input type="text" class="effect-time"/></td>-->
                    </tr>
                    </tbody>
                </table>
            </div>
            <div class="rule-section">
                <table class="rule-bizScene">
                    <tbody>
                    <tr>
                        <td class="label-name">关联业务板块：</td>
                        <td class="label-content">
                            <select class="select-sence">
                            </select>
                        </td>
                        <!--<td class="label-relation">&nbsp;</td>
                        <td class="label-relationDesc">&nbsp;</td>
                        <td>&nbsp;</td>-->
                        <td class="label-name">状态：</td>
                        <td class="label-content">
                            <select class="select-policy-status">
                                <option value="0">草稿</option>
                                <option value="1">生效</option>
                            </select>
                        </td>
                        <td class="label-name">生效时间：</td>
                        <td class="label-content"><input type="text" class="effect-time"/></td>
                    </tr>
                    </tbody>
                </table>
                <table class="rule-groupTable rule-groupTable-template">
                    <thead>
                    <tr>
                        <td class="label-name">规则小组01</td>
                        <td class="label-content">
                            <button type="button" class="btn btn-blue btn-small btn-add btn-rule">
                                增加
                            </button>
                            <button type="button"
                                    class="btn btn-blue btn-small btn-delete btn-rule btn-special">
                                删除
                            </button>
                        </td>
                        <td class="label-relation">&nbsp;</td>
                        <td class="label-relationDesc">&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    </thead>
                    <tbody>
                    <tr class="rule-tr-template">
                        <td class="label-name">关联内容：</td>
                        <td class="label-content">
                            <select class="select-rule-eft-item">
                                <!-- <option value="0">运抵国</option>
                                <option value="1">目的国</option> -->
                            </select>
                        </td>
                        <td class="label-relation">
                            <select class="select-expression-relation">
                                <option value="CN">包含</option>
                                <option value="NC">非包含</option>
                                <option value="EQ">等于</option>
                                <option value="NE">不等于</option>
                                <option value="LT">小于</option>
                                <option value="GT">大于</option>
                            </select>
                        </td>
                        <td class="label-relationDesc"><input type="text" class="relation-desc"/>
                        </td>
                        <td>
                            <button type="button" class="btn btn-blue btn-small btn-add btn-rule">
                                增加
                            </button>
                            <button type="button"
                                    class="btn btn-blue btn-small btn-delete btn-rule btn-special">
                                删除
                            </button>
                        </td>
                    </tr>
                    <!-- <tr>
                        <td class="label-name">&nbsp;</td>
                        <td class="label-content">
                            <div class="rule-relation-expression">
                                <div class="or-expression"><input type="radio" name="expression-radio"/>或</div>
                                <div class="and-expression"><input type="radio" name="expression-radio"/>与</div>
                                <div class="clean"></div>
                            </div>
                        </td>
                        <td class="label-relation">&nbsp;</td>
                        <td class="label-relationDesc">&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="label-name">关联内容：</td>
                        <td class="label-content">
                            <select name="" id="">
                                <option value="0">运抵国</option>
                                <option value="1">目的国</option>
                            </select>
                        </td>
                        <td class="label-relation">
                            <select name="" id="">
                                <option value="CN">包含</option>
                                <option value="NC">非包含</option>
                                <option value="EQ">等于</option>
                                <option value="NE">不等于</option>
                                <option value="LT">小于</option>
                                <option value="GT">大于</option>
                            </select>
                        </td>
                        <td class="label-relationDesc"><input type="text" /></td>
                        <td>
                            <button type="button" class="btn btn-blue btn-small">增加</button>
                            <button type="button" class="btn btn-blue btn-small">删除</button>
                        </td>
                    </tr> -->
                    </tbody>
                </table>
                <!-- <div class="tables-relations">
                    <div class="rule-relation-expression rule-relation-expression-sm">
                        <div class="or-expression"><input type="radio" name="expression-radio"/>或</div>
                        <div class="and-expression"><input type="radio" name="expression-radio"/>与</div>
                        <div class="clean"></div>
                    </div>
                </div>
                <table class="rule-groupTable">
                    <thead>
                        <tr>
                            <td class="label-name">规则小组02</td>
                            <td class="label-content">
                                <button type="button" class="btn btn-blue btn-small">增加</button>
                                <button type="button" class="btn btn-blue btn-small">删除</button>
                            </td>
                            <td class="label-relation">&nbsp;</td>
                            <td class="label-relationDesc">&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td class="label-name">关联内容：</td>
                            <td class="label-content">
                                <select name="" id="">
                                    <option value="0">运抵国</option>
                                    <option value="1">目的国</option>
                                </select>
                            </td>
                            <td class="label-relation">
                                <select name="" id="">
                                    <option value="CN">包含</option>
                                    <option value="NC">非包含</option>
                                    <option value="EQ">等于</option>
                                    <option value="NE">不等于</option>
                                    <option value="LT">小于</option>
                                    <option value="GT">大于</option>
                                </select>
                            </td>
                            <td class="label-relationDesc"><input type="text" /></td>
                            <td>
                                <button type="button" class="btn btn-blue btn-small">增加</button>
                                <button type="button" class="btn btn-blue btn-small">删除</button>
                            </td>
                        </tr>
                        <tr>
                            <td class="label-name">&nbsp;</td>
                            <td class="label-content">
                                <div class="rule-relation-expression">
                                    <div class="or-expression"><input type="radio" name="expression-radio"/>或</div>
                                    <div class="and-expression"><input type="radio" name="expression-radio"/>与</div>
                                    <div class="clean"></div>
                                </div>
                            </td>
                            <td class="label-relation">&nbsp;</td>
                            <td class="label-relationDesc">&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td class="label-name">关联内容：</td>
                            <td class="label-content">
                                <select name="" id="">
                                    <option value="0">运抵国</option>
                                    <option value="1">目的国</option>
                                </select>
                            </td>
                            <td class="label-relation">
                                <select name="" id="">
                                    <option value="CN">包含</option>
                                    <option value="NC">非包含</option>
                                    <option value="EQ">等于</option>
                                    <option value="NE">不等于</option>
                                    <option value="LT">小于</option>
                                    <option value="GT">大于</option>
                                </select>
                            </td>
                            <td class="label-relationDesc"><input type="text" /></td>
                            <td>
                                <button type="button" class="btn btn-blue btn-small">增加</button>
                                <button type="button" class="btn btn-blue btn-small">删除</button>
                            </td>
                        </tr>
                    </tbody>
                </table> -->
            </div>
            <div class="warn-section">
                <table class="warn-table">
                    <tbody>
                    <tr>
                        <td class="label-name">提醒内容：</td>
                        <td>
                            <textarea class="textarea-warn-content" rows="5" id="content"
                                      name="content"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td class="label-name">备注说明：</td>
                        <td>
                            <textarea class="textarea-warn-remark" rows="5" id="remark"
                                      name="remark"></textarea>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div class="btn-section">
                <button type="button" class="btn btn-blue btn-back">返回</button>
                <button type="button" class="btn btn-blue btn-save">提交</button>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" src="../assets/js/jquery.js"></script>
<script type="text/javascript" src="../assets/plugin/jquery-ui-1.12.1.custom/jquery-ui.js"></script>
<script type="text/javascript" src="../assets/plugin/layer/layer.js"></script>
<script type="text/javascript" src="../assets/js/rule.js"></script>
<!--<script type="text/javascript" src="../../../data-type.js"></script>-->
<script type="text/javascript">
    $(document).ready(function () {
        _PROTOTYPE_._init();
        $(".btn-section").find(".btn-blue").on("click", function () {
            if ($(this).hasClass("btn-save")) {
                var temp = JSON.stringify(_PROTOTYPE_._getFormParams());
                var submitParams = '{"data":' + temp + '}';
                /*submitParams.data = JSON.stringify(_PROTOTYPE_._getFormParams());*/
                console.log(submitParams);
                var content = $(".textarea-warn-content");
                var remark = $(".textarea-warn-remark");

                if (charLength(content.val()) > 200) {
                    alert("提醒内容不能超过200字符");
                    content.focus()
                    return;
                }
                if (charLength(remark.val()) > 400) {
                    alert("备注不能超过400字符");
                    remark.focus()
                    return;
                }
                $.ajax({
                           /*url:'../assets/js/testData/response.js',*/
                           url: '/policyRules/manage/save',
                           type: 'post',
                           contentType: 'application/json',
                           /*traditional: true,*/
                           data: submitParams,
                           dataType: 'json',
                           success: function (data) {
                               console.log(data);
                               if (data.error_code == 0) {
                                   location.href = "/policyRules/listPage";
                               } else {
                                   alert("系统内部错误");
                               }
                           },
                           error: function (a, b, c) {
                               console.log(b);
                           }
                       })
                /*console.log(_PROTOTYPE_._getFormParams());*/
            } else {
                history.go(-1);
            }
        });
        $("body").on("change", ".select-expression-relation", function () {
            var val = $(this).find("option:selected").val();
            if (val != 'CN' && val != 'NC') {
                $(this).parent().next().find(".relation-desc").attr("data-type",
                                                                    "float").val("");
            } else {
                $(this).parent().next().find(".relation-desc").removeAttr("data-type").val("");
            }
        });
        if (!$.fn.dataType) {
            $.fn.dataType = {};
        }
        $.fn.dataType.config = {
            "int": {char: /\d/, text: /0|[1-9]\d*/},
            "float": {char: /\d|\./, text: /^(0|[1-9]\d*)(\.\d*)?$/}
        };
        var events = {};
        $.each($.fn.dataType.config, function (i, n) {
            events[i] = function (e) {
                var char = String.fromCharCode(e.keyCode);
                return n.char.test(char) && n.text.test($(this).val() + char);
            };
        });
        $("body").on("keypress", 'input[data-type]', function (e) {
            var dataType = $(this).attr("data-type");
            var event = events[dataType];
            if (event) {
                return event.call(this, e);
            }
        });
        $("body").on("keyup", 'input[data-type]', function (e) {
            var val = $(this).val();
            val = val.replace(/[\u4e00-\u9fa5]/g, '');
            $(this).val(val);
        });
    });

    /**
     *@author han
     *判断中英文字符串的长度
     **/
    function charLength(val) {
        var len = 0;
        for (var i = 0; i < val.length; i++) {
            if (val[i].match(/[^x00-xff]/ig) != null) //全角
            {
                len += 2;
            } else {
                len += 1;
            }
        }
        ;
        return len;
    }
</script>
</body>
</html>
